package Ep02_LinkedList.Offer_06;

import Ep02_LinkedList.ListNode;

import java.util.ArrayList;

/**
 * @author Jimmy Zhan WORKSTATION
 * @since 2023/7/13 11:37
 * 说明：
 *      方法一：因为是从尾到头，因此不知道数组的长度，考虑使用递归，递归也可以记录遍历链表每个节点的状态
 */

public class Mine2 {
    public int[] reversePrint(ListNode head) {
        if (head == null) return new int[0];
        ArrayList<Integer> al = new ArrayList<>();
        while(head != null) {
            al.add(head.val);
            head = head.next;
        }
        int size = al.size();
        int[] res = new int[size];
        for(int i = 0; i < size; ++i){
            res[i] = al.get(size - i - 1);
        }
        return res;
    }
}
